function mapSafeSet(map, ...sets) {
    var currentMap = map;
    var keys = sets.slice(0, sets.length - 1);
    var value = sets[sets.length - 1];
    if (sets.length < 2) {
        value = {};
    }
    keys.forEach(function (key, index) {
        if (index == keys.length - 1) {
            var ret = {};
            ret[key] = value;
            currentMap = Object.assign(currentMap, ret);
        } else {
            if (!currentMap.hasOwnProperty(key)) {
                currentMap[key] = {};
            }
            currentMap = currentMap[key];
        }
    })
}

module.exports = {
    mapSafeSet
};